package logs

import (
	"epg-mc/database/table/config"
	"net/http"

	"github.com/labstack/echo"
)

var base *Base

//Base template data
type Base struct {
	data map[string]interface{}
}

func init() {
	base = &Base{data: make(map[string]interface{})}
	base.data["title"] = config.GetValue(config.SiteTitle)
	base.data["uname"] = ""
}

//Index url:/admin/setting/index
func Index(c echo.Context) error {
	base.data["uname"] = c.Get("uname")
	base.data["data"] = config.GetAll()
	err := c.Render(http.StatusOK, "logs/index.html", base.data)

	return err
}

func SlowQuery(c echo.Context) error {
	base.data["uname"] = c.Get("uname")
	base.data["data"] = config.FindByKey(config.SlowQueryAPI)
	err := c.Render(http.StatusOK, "logs/slowquery.html", base.data)

	return err
}

func ErrorLog(c echo.Context) error {
	base.data["uname"] = c.Get("uname")
	base.data["data"] = config.FindByKey(config.ErrorLogAPI)
	err := c.Render(http.StatusOK, "logs/errorlog.html", base.data)
	return err
}
